<?php

namespace app\common\model\xiluedu;

use app\common\library\Auth;
use think\Db;
use think\Log;
use think\Model;
use traits\model\SoftDelete;
use function fast\array_get;

class CourseFile extends Model
{

    // 表名
    protected $name = 'xiluedu_course_file';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'type_text',
        'is_free_text',
        'status_text'
    ];

    
    public function getTypeList()
    {
        return ['1' => __('Type 1'), '2' => __('Type 2')];
    }

    public function getIsFreeList()
    {
        return ['0' => __('Is_free 0'), '1' => __('Is_free 1')];
    }


    public function getStatusList()
    {
        return ['0' => __('Status 0'), '1' => __('Status 1')];
    }
    #封面图
    public function getPosterImageAttr($value,$data){
        return $value ? cdnurl($value,true) :'';
    }
    #视频文件
    public function getFileAttr($value,$data){
        return $value ? cdnurl($value,true) :'';
    }

    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getIsFreeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_free']) ? $data['is_free'] : '');
        $list = $this->getIsFreeList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }
}
